<template>
  <div class="home_p">
    <el-container>
      <el-header class="header">
        <div class="title">
          <img src="../assets/img/heima.png" alt />
          <span>电商后台管理系统</span>
        </div>
        <el-button type="message" @click="logout" class="logout_btn">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside class="el-aside" :width="!isShensuo ? '200px':'64px'">
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#333744"
            text-color="#fff"
            unique-opened 
            router
            :default-active="path"
            :collapse-transition="false"
            :collapse="isShensuo"
            active-text-color="blue"
          >
            <div class="ss_btn" @click="shensuo">|||</div>
            <el-submenu :index="item.id+''" v-for="item in subnavList.data" :key="item.id">
              <template slot="title">
                <i :class="iconList[item.id]"></i>
                <span class="two">{{item.authName}}</span>
              </template>
              <el-menu-item  :index="'/'+citem.path" v-for="citem in item.children" :key="citem.id" @click="activePath('/'+citem.path)">
                <i class="el-icon-menu" ></i>
                {{citem.authName}}
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main class="main">
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data: function() {
    return {
      subnavList: {},
      iconList: {
        '125': 'fa fa-users',
        '103': 'fa fa-cog',
        '101': 'fa fa-heart',
        '102': 'fa fa-file-text',
        '145': 'fa fa-line-chart'
      },
      isShensuo: false,
      path:''
    }
  },
  async created() {
    const { data: res } = await this.$http.get('menus')
    this.subnavList = res
    this.path = window.sessionStorage.getItem('path')
  },
  methods: {
    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    shensuo() {
      this.isShensuo = !this.isShensuo
    },
    activePath(path1){
      this.path = path1
      window.sessionStorage.setItem('path',path1)
      this.$router.push(this.path)
    }
  }
}
</script>

<style lang="less" scoped>

.home_p {
  height: 100%;
  background-color: #fff;
  color: #fff;
}
.header {
  background-color: #373d41;
  padding: 0;
  img {
    vertical-align: bottom;
  }
  span {
    font-size: 20px;
    line-height: 60px;
    padding-left: 80px;
  }
}
.el-container {
  height:100%;
}
.el-menu {
  border: none;
}
.el-submenu .el-menu-item {
  min-width: 199px;
}
.two {
  padding-left: 10px;
}
.el-aside {
  background-color: #333744;
}
.main {
  color: #000;
  background-color: #eaedf1;
}
.title {
  float: left;
}
.logout_btn {
  float: right;
  margin: 10px;
}
.ss_btn {
  width: 100%;
  height: 30px;
  background-color: #ff5000;
  line-height: 30px;
  font-size: 15px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}

</style>